/**********************************************************************************
 * class Explorer
 *******************************/
(function(){

    /**
     * 构造函数
     */
    var Explorer = window.Explorer = function( subject )
    {
        // 注册(观察者)
        if( subject ){
            subject.attach(this);
        }

        // 命令对象
        this.cmdDir = new CmdBuilder( "explorer","dir","null" );

        // 功能模块对象
        this.dir = new Directory();
    }

    Explorer.fn = Explorer.prototype =
    {
        listening : function(cmd)
        {
            if(cmd.subsys != this.cmdDir.subsys ){  return false;    }

            var dispArea = Explorer.ui.init();
            dispArea.content.append("<h1>Explorer</h1>");
            //this.directoryCall( cmd,this.dispArea );   // 功能接口调用

        },

            // Directory 接口调用
        directoryCall : function(cmd,dispArea)
        {
            switch( cmd.service ){

              case this.cmdDir.module+"/list":
                  var dispArea = Explorer.ui.init();
                  this.dir.get_dirList(dispArea.content);
                  break;

              default:
                  var dispArea = Explorer.ui.init();
                  this.dir.get_dirList(dispArea.content);
                  break;

                  //dir.get_fileList(dispObj);
            }
        }
    };

    // Ui
    Explorer.ui = {
        topToolbar: "",
        content: "",
        bottomToolbar: "",

        init : function(){
            this.topToolbar = App.ui.toolbarWrap.clone(true);
            this.content = App.ui.contentWrap.clone(true);
            this.bottomToolbar =this.topToolbar.clone(true);

            App.ui.content.empty()             //主显示区域
                  .append(this.topToolbar)     //工具显示区域
                  .append(this.content)        //内容显示区域
                  .append(this.bottomToolbar);

            this.topToolbar.append(App.ui.btnReturn.clone(true));       //填充顶部工具
            this.bottomToolbar.append(App.ui.btnReturn.clone(true));    //填充底部工具条

            return this;
        }
    };
})(jQuery);



/**********************************************************************************
 * class Directory
 *******************************/
(function(){

    /**
     * 构造函数
     */
    var Directory = window.Directory = function( exeFile,subsysCmd,moduleCmd,childModuleCmd )
    {
        //
    }

    /**
     * 页面, <method>
     */
    Directory.fn = Directory.prototype =
    {
        get_dirList : function(cmd,dispObj)
        {

            var instance = this;
            var page = $("#explorer_directory_list").clone();
            page[0].id = "explorer_directory_list_clone";

            var a = location.hash.split('///');
            if( 1 == a.length ){  a[0] = "";    }

            var folder = a[a.length-1];
            var upFolder = folder.substring( 0, folder.lastIndexOf("/") );
            page.find(".up").attr( "href", "#explorer/directory/listJson///" + upFolder );
            page.find(".reload").attr( "href", "#explorer/directory/listJson/"+ Math.random() +"///" + a[a.length-1] );

            $.getJSON( "appLoad.aspx?cmd=explorer/dir/getDirs&path=" + a[a.length-1],function( json ){

                  var content = "<ul>";
                  for( var i in json ){
                      content += "<li><a href=\"#explorer/dir/getDirs///" + json[i] + "\">" + json[i] + "</a></li>";
                  }
                  content += "</ul>";

                  page.append( content );
                  dispObj.append( page );
            });

        },

        get_fileList : function(dispObj){

        }
    }
})(jQuery);